<!DOCTYPE HTML>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="maximum-scale=1.0, minimum-scale=1.0, user-scalable=0, initial-scale=1.0, width=device-width"/>
        <meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
        <title>统战成员学习平台</title>
	    <link rel="stylesheet" type="text/css" href="../../css/base.css" />
        <link rel="stylesheet" type="text/css" href="../../css/style.css" />
    </head>
    <body class="white">
        <header class="white red">
            <div class="ui_border_b">
                <span tapmode onclick="closeFrame()" class="left"><i class="icon_back_white"></i></span>
                <p>写评论</p>
                <span tapmode onclick="submit()" class="right white">发表</span>
            </div>
    	</header>
        <div id="app" style="display:none" v-show="true" class="comment_area">
            <img :src="imageBasePath + usrImg" onerror="this.src=''">
            <textarea v-model="content" placeholder="添加评论（100字以内）" maxlength="100" id="comment_textarea"></textarea>
        </div>
        <script type="text/javascript" src="../../script/api.js"></script>
		<script type="text/javascript" src="../../script/vue.min.js"></script>
        <script type="text/javascript" src="../../script/common.js"></script>
        <script type="text/javascript" src="../../script/layer_mobile/layer.js"></script>
        <script type="text/javascript">
            var app = new Vue({
                el: '#app',
                data: {
                    imageBasePath: imageBasePath,
                    courseId: 0,
                    height: 400,
                    content: '',
                    usrImg: '',
                    submiting: false
                },
                mounted: function() {
                    var $this = this;
                    apiready = function(){
                        sbsm.set('dark');
                        $this.courseId = api.pageParam.courseId;
                        api.parseTapmode();
                        // fix header
                        var header = $api.dom('header');;
                        $api.fixStatusBar(header);
                        var userInfo = $api.getStorage(_.USERINFO);
                        $this.usrImg = userInfo.usrImg;
                        setTimeout(function() {
                            $this.height = api.frameHeight - $api.offset(header).h;
                        }, 0)

                        $api.byId('comment_textarea').addEventListener('click',function(){
                            $api.byId('comment_textarea').focus();
                        });
                    };
                },
                methods: {
                    submit: function() {
                        var $this = this;
                        if($this.submiting) return;
                        if(!$this.content.length) return msgUtil.toast({msg: '请输入评论'});
                        $this.submiting = true;
                        post('/client/courseMsg/add', {
                            courseId: $this.courseId,
                            content: $this.content
                        }, function(ret) {
                            if(ret.isSuccess) {
                                msgUtil.toast({
                                    msg: ret.message || '发表成功'
                                });
                                api.sendEvent({
                                    name: 'refresh_lesson_comment_event'
                                });
                                setTimeout(function() {
                                    closeFrame();
                                }, 500)
                            } else {
                                msgUtil.toast({
                                    msg: ret.message
                                });
                            }
                        });
                    }
                }
            });

            function submit(){
                app.submit()
            }

            function closeFrame() {
                $api.byId('comment_textarea').blur();
                $api.rmStorage(_.LSEESONCOMMENT);
                sbsm.closed();
                api.closeWin()
            }
        </script>
    </body>
</html>
